#include <stdio.h>
#include <time.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
    FILE *fp;

    fp = fopen("time.txt", "a+");
    time_t s;
    struct tm *t;

     while(1)
     {
         s = time(NULL);
         t = localtime(&s);
        fprintf(fp, 
                "%4d年%2d月%2d日 %2d:%2d:%2d\n", 
                t->tm_year + 1900,
                t->tm_mon + 1,
                t->tm_mday,
                t->tm_hour,
                t->tm_min,
                t->tm_sec);
        printf( "%4d年%2d月%2d日 %2d:%2d:%2d\n", 
                t->tm_year + 1900,
                t->tm_mon + 1,
                t->tm_mday,
                t->tm_hour,
                t->tm_min,
                t->tm_sec);
        fflush(fp);
        sleep(1);
     }

    if (fclose(fp) == EOF) {
        perror("fclose");
        return EOF;
    }

    return 0;
}
